package com.example.trafficsystem.controller;

import com.example.trafficsystem.entity.Exam;
import com.example.trafficsystem.entity.ExamQuestion;
import com.example.trafficsystem.entity.ExamRecord;
import com.example.trafficsystem.service.ExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/exams")
@CrossOrigin
public class ExamController {

    @Autowired
    private ExamService examService;

    // 获取培训计划的考试
    @GetMapping("/trainingPlan/{trainingPlanId}")
    public Exam getExamForTrainingPlan(@PathVariable Long trainingPlanId) {
        return examService.getExamForTrainingPlan(trainingPlanId);
    }

    // 获取考试题目
    @GetMapping("/{examId}/questions")
    public List<ExamQuestion> getExamQuestions(@PathVariable Long examId) {
        return examService.getExamQuestions(examId);
    }

    // 学员开始考试
    @PostMapping("/start/{studentId}/{examId}")
    public ExamRecord startExam(@PathVariable Long studentId, @PathVariable Long examId) {
        return examService.startExam(studentId, examId);
    }

    // 提交考试
    @PostMapping("/submit/{examRecordId}")
    public ExamRecord submitExam(@PathVariable Long examRecordId, @RequestBody List<Object> answers) {
        return examService.submitExam(examRecordId, answers);  // 调用服务层处理提交
    }

    // 获取考试记录
    @GetMapping("/record/{examRecordId}")
    public ExamRecord getExamRecord(@PathVariable Long examRecordId) {
        return examService.getExamRecord(examRecordId);
    }
}
